<?php

namespace App\Models;

use App\Traits\ActionButtonAttributeTrait;
use GeniusTS\Roles\Models\Role as Model;

class Role extends Model
{
    use ActionButtonAttributeTrait;

    const LOCATION_PRE = 'location.';

    private $action = 'role';

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
    }

    public function setLevelAttribute($value)
    {
        if ($value && is_numeric($value)) {
            $this->attributes['level'] = intval($value);
        } else {
            $this->attributes['level'] = 1;
        }
    }

    /**
     * 获取大区
     * @param $query
     * @return mixed
     */
    public function scopeLocation($query)
    {
        return $query->where('slug', 'like', 'location.%');
    }
}
